# demo04_exception.py
# else: 如果try中代码不出异常，则执行else中的内容
# finally: 不论try中代码报错与否，
#          都会执行finally中的代码块,一般用于对资源的关闭
try:  # 将可能出错的代码放到try代码块中
    n1 = int(input("num01: "))
    n2 = int(input("num02: "))
    data = n1 / n2
except ValueError:  # except 错误类型 as 变量名:
    print("请您输入整数!!!")
except ZeroDivisionError as e:
    print("reason:", e)
except (KeyboardInterrupt, EOFError):  # ctrl+c/d
    print("Byebye~")
    exit()  # 退出程序
except Exception as e:  # 兜底方案
    print("reason:", e)
else:
    print("data:", data)
finally:
    print("finally ok~")
print("hello world")

# try:
#     fr = open("/etc/passwd", mode="r")
#     fr.readline()
#     a = 10/0
# ......
# finally:
#     fr.close()
